from models import *


def get_default_user():
    query = db.Query(User).filter("email = " , DEFAULT_USER_EMAIL)
    if query.count() > 0:
        return query[0]
    else:
        return None

def get_problem_by_id(id):
    return Problem.get(id)

def get_initial_problem(user):
    query = db.Query(Problem).filter("person = ", user).filter("is_initial_problem = ", True)
    if query.count() > 0:
        return query[0]
    else:
        return None
    
def get_problem_causes(user, p):
    return db.Query(CausalRelation).filter("person = ", user).filter("effect = ", p)
